<template>
    <div>
        <div class="box">
            <div class="logo_box_bg"><img src="../assets/login_bg.jpg"/></div>
            <div class="logo_box_bg_meng"></div>
            <div class="login_box">
                <div class="login_logo">
                    <img src="../assets/logo.png" style="width:100%"/>
                </div>
                <div class="login_from">
                    <div class="login_top">
                        <el-tabs v-model="activeName">
                            <el-tab-pane label="广告主登录" name="ad"></el-tab-pane>
                            <el-tab-pane label="媒体登录" name="media"></el-tab-pane>
                        </el-tabs>
                    </div>
                    <div class="login_middle">
                        <el-input placeholder="请输入登录时使用的账号，请确保可用" v-model="account" class="el_input"
                                  style="width:100%!important;height: 40px;" @keyup.enter.native="login">
                        </el-input>
                        <!--<span class="login_parton">*必填</span>-->
                        <el-input type="password" placeholder="请输入密码" v-model="password" class="el_input"
                                  @keyup.enter.native="login" style="width:100%!important;height: 40px;">
                        </el-input>
                        <!--<span class="login_parton">*必填</span>-->
                    </div>
                    <div class="login_bottom" @click="login">登录</div>
                </div>

            </div>
        </div>
    </div>
</template>

<script>
    //    import crypto from 'crypto';

    export default {
        data() {
            return {
                account: '',
                password: '',
                md5Password: '',
                activeName: 'ad',
            };
        },
        created() {
        },
        methods: {
            md(str) {
                var md5 = crypto.createHash('md5');
                md5.update(str);
                return md5.digest('hex');
            },
            login() {
                if(this.activeName=='media'){
                    this.$message({
                        type: 'info',
                        message: '该账号不存在'
                    });
                }else if (this.account == '') {
                    this.$message({
                        type: 'info',
                        message: '请输入用户名'
                    });
                } else if (this.password == '') {
                    this.$message({
                        type: 'info',
                        message: '请输入密码'
                    });
                } else {
//                    this.md5Password = this.md(this.password);
                    this.$http({
                        method: 'post',
                        url: this.apiUrl.login,
                        data: {
                            name: this.account,
                            pwd: this.password
                        }
                    }).then(res => {
                        if (res.status == 200) {
//                            console.log(res);
                            var data=res.data;
                            if(data.status==1){
                                this.set_storage('userName', this.account);
//                                this.setCookie('USER_LOGIN',data.userId,1);
//                                console.log(this.getCookie('USER_LOGIN'));
                                this.$router.push({path: sessionStorage.url||'/ads/admana'});
                            }else{
                                this.$message({
                                    type: 'error',
                                    message: data.message
                                });
                            }
                        } else {
                            this.$message({
                                type: 'error',
                                message: '用户名或密码错误'
                            });
                        }
                    }).catch(error => {
                        console.log(error);
                    });
                }
            }
        }
    };
</script>
<style rel="stylesheet/css" lang="scss">

</style>
